package com.yzh.homework;

import java.io.*;

/**
 * @author 于振晗
 * @title: HomeWork01
 * @description: TODO 1.	分别使用文件流和缓冲流复制一个长度大于100MB的视频文件，并观察效率的差异。
 * @date 2020年09月07日
 * @path com.yzh.homework
 */
public class HomeWork01 {
    public static void main(String[] args) throws IOException {
        long l11 = System.currentTimeMillis();
        ByteTest.copyVideo();
        long l12 = System.currentTimeMillis();
        System.out.println("文件流"+(l12-l11));
        long l21 = System.currentTimeMillis();
        BufferTest.copyVideo();
        long l22 = System.currentTimeMillis();
        System.out.println("缓冲流"+(l22-l21));

    }
}

//字节流
class ByteTest{
    public static void copyVideo() throws IOException {
        //读取视频文件
        FileInputStream fis = new FileInputStream("d:/test/test.mp4");
        FileOutputStream fos = new FileOutputStream("d:/test/test1.mp4");
        byte [] byt = new byte[1024];
        //复制
        int len = 0;
        while ((len = fis.read(byt)) != -1) {
            fos.write(byt,0,len);
        }
        fis.close();
        fos.close();
    }
}




class BufferTest{
    public static void copyVideo() throws IOException {
        //读取视频文件
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("d:/test/test.mp4"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("d:/test/test2.mp4"));
        byte [] byt = new byte[1024];
        //复制
        int len = 0;
        while ((len = bis.read(byt)) != -1) {
            bos.write(byt,0,len);
        }
        bis.close();
        bos.close();
    }
}
